vim.g.mapleader = ","

local keymap = vim.keymap

-- ------------------- 插入模式 -------------------
keymap.set("i", "jk", "<ESC>")

-- ------------------- 视觉模式 -------------------
-- 选中状态代码向上移动
keymap.set("v", "J", ":m '>+1<CR>gv=gv")
-- 选中状态代码向下移动
keymap.set("v", "K", ":m '<-2<CR>gv=gv")

-- ------------------- 正常模式 -------------------
-- 窗口分隔
keymap.set("n","<leader>sv","<C-w>v")
keymap.set("n","<leader>sh","<C-w>s")

-- 光标相对移动
keymap.set("n","gj","j")
keymap.set("n","gk","k")
keymap.set("n","j","gj")
keymap.set("n","k","gk")

-- 取消高亮
keymap.set("n","<leader>nh",":nohl<CR>")

-- 更换缓冲区
keymap.set("n","<leader>bn",":bnext<CR>")
keymap.set("n","<leader>bp",":bprevious<CR>")

-- 删除缓冲区
keymap.set("n","<leader>bb",":bdelete<CR>")

-- 更换参数区
keymap.set("n","<leader>an",":next<CR>")
keymap.set("n","<leader>ap",":previous<CR>")

-- 保存
keymap.set("n","<leader>w",":w<CR>")
-- 保存并运行python
keymap.set("n","<leader>wp",":w | !python3 %<CR>")
-- 保存并运行pipenv run flask run
keymap.set("n","<leader>wf",":w | !pipenv run flask run<CR>")

-- ------------------- 系统剪切板操作 -------------------
-- 复制当前选中到系统剪切板
keymap.set("v", "<leader><leader>y", "\"+y<CR>")
-- 将系统剪切板内容粘贴到vim
keymap.set("n","<leader><leader>p","\"+p<CR>")


-- ------------------- 插件 -------------------
-- nvim-tree
keymap.set("n","<leader>n",":NvimTreeToggle<CR>")

-- floaterm
keymap.set("t","<leader>t","<C-\\><C-N>:FloatermToggle<CR>")
keymap.set("t","<leader>tk","<C-\\><C-N>:FloatermKill<CR>")
keymap.set("t","<leader>tn","<C-\\><C-N>:FloatermNext<CR>")
keymap.set("t","<leader>tp","<C-\\><C-N>:FloatermPrev<CR>")
keymap.set("t","<leader>tu","<C-\\><C-N>:FloatermUpdate<CR>")
keymap.set("n","<leader>t",":FloatermToggle<CR>")
keymap.set("n","<leader><leader>t",":FloatermNew<CR>")

